import smtplib
from email import encoders
from email.mime.text import MIMEText
from email.mime.base import MIMEBase
from email.mime.multipart import MIMEMultipart
from email.header import Header

def pri():
    print('ssdd')

def send_email():
    print("send_email called!")
    # 发件人邮箱
    sender = 'yunwei@aiseep.com'
    # 发件人邮箱密码（如果是第三方客户端授权码）
    password = 'YwkuJqu1Uhbzetsq'
    # 收件人邮箱
    # receivers = ['houenxing@enemind.com']
    receivers=['houenxing@enemind.com', 'wangxuezhi@enemind.com', '358206985@qq.com']

    # 创建一个带附件的邮件对象
    message = MIMEMultipart()
    message['From'] = Header(sender)
    message['To'] = ", ".join(receivers)
    message["Subject"] = "招标网每日招标信息更新（测试中）"

    # 邮件正文内容
    content = '附件是从招标网获取的碳盘查、碳系统、绿色供应链、碳咨询、碳足迹、碳达峰、绿色工厂、绿色园区数据，请查收。'
    message.attach(MIMEText(content, "plain", 'utf-8'))

    # 附件文件名
    filename = "zhaobiaowang.xlsx"

    # 打开文件并附加到邮件中
    with open(filename, "rb") as attachment:
        part = MIMEBase("application", "octet-stream")
        part.set_payload(attachment.read())

    encoders.encode_base64(part)
    part.add_header(
        "Content-Disposition",
        f"attachment; filename= {filename}",
    )
    message.attach(part)

    try:
        smtpObj = smtplib.SMTP_SSL('smtphz.qiye.163.com', 465)
        smtpObj.login(sender, password)
        smtpObj.sendmail(sender, receivers, message.as_string())
        print("邮件发送成功")
    except Exception as e:
        print(f"邮件发送失败：{e}")
    finally:
        smtpObj.quit()